<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>倒计时效果</title>
    <link rel="stylesheet" href="../css/common.css">
    <style>
        #time{
            width: 200px;
            height: 60px;
            background-color: red;
            margin: 50px;
            color: white;
            font-size: 20px;
        }
        #h,#m,#s{
            width: 40px;
            height: 40px;
            background-color: black;
            color: white;
            text-align: center;
            line-height: 40px;
        }
        .split{
            width: 20px;
            text-align: center;
        }
    </style>
</head>
<body>
    <div id="time" class="flex a-c j-c">
        <div id="h">02</div>
        <div class="split">:</div>
        <div id="m">44</div>
        <div class="split">:</div>
        <div id="s">33</div>
    </div>
    <script src="../js/bing.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
    <script>
        let endDate = new Date('2020-12-31 12:30:0')
        //使用定时器，实现倒计时
        // setInterval(() => {
        //     let ms = endDate - new Date()
        //     //获取小时
        //     let h = Math.floor(ms / 1000 / 3600)
        //     //获取分钟
        //     let m = Math.floor(ms / 1000 % 3600 / 60)
        //     //获取秒
        //     let s = Math.floor(ms / 1000 % 60)
        //     $('#h').text($b.repairZero(h))
        //     $('#m').text($b.repairZero(m))
        //     $('#s').text($b.repairZero(s))
        // }, 800);

        setInterval(() => {
            //调用获取两个日期间隔：时分秒的方法
            let hms = $b.getHMS(endDate)
            $('#h').text(hms.h)
            $('#m').text(hms.m)
            $('#s').text(hms.s)
        }, 800);
    </script>
</body>
</html>